package w4156.idog.server;

import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import w4156.idog.model.User;


/**
 * Session Bean implementation class Test
 */
@Stateless(mappedName = "TestEJB")
@TransactionManagement(TransactionManagementType.BEAN)
public class Test implements TestRemote {
	
	@PersistenceContext(unitName="defaultPersistenceUnit") 
	private EntityManager em;
	
	@Override
	public String testEJB() {
		return "EJB works well!";
	}

	@Override
	public String testDB() {
		Query q = em.createQuery("SELECT u FROM User u");
		q.setMaxResults(1);
		return ((User)q.getSingleResult()).getName();
	}

}
